import jwt
from datetime import datetime, timedelta
from django.conf import settings
from rest_framework import status
from rest_framework.decorators import api_view
from rest_framework.response import Response
from .models import *
from .serializers import *
import random
from rest_framework.pagination import PageNumberPagination

# 验证token
from rest_framework.exceptions import AuthenticationFailed
# 短信验证码
import json
import requests
from urllib.parse import urlencode

# 邮箱验证码
from django.core.mail import send_mail

# 导出 Excel
from django.http import HttpResponse
from openpyxl import Workbook


# 验证token
def verify_token(token):
    try:
        decoded_payload = jwt.decode(token, settings.SECRET_KEY, algorithms=['HS256'])
        # Perform additional checks if needed
        return decoded_payload
    except jwt.ExpiredSignatureError:
        raise AuthenticationFailed('Token has expired')
    except jwt.InvalidTokenError:
        raise AuthenticationFailed('Invalid token')


# 实现发送验证码逻辑
@api_view(['POST'])
def send_verification_code(request):
    code = random.randint(100000, 999999)
    phone_number = json.loads(request.body).get('phone_number')
    print(phone_number)

    # 检查验证码是否存在
    if SMSVerification.objects.filter(phone_number=phone_number).exists():
        return Response({'message': '验证码已发送', 'status': status.HTTP_400_BAD_REQUEST, "code": code}, status=status.HTTP_200_OK)
    else:
        SMSVerification.objects.create(phone_number=phone_number, code=code)
        # url = "http://v.juhe.cn/sms/send"
        # params = {
        #     "mobile": phone_number,  # 接受短信的用户手机号码
        #     "tpl_id": "245380",  # 您申请的短信模板ID，根据实际情况修改
        #     "tpl_value": "#code#={}".format(code),  # 您设置的模板变量，根据实际情况修改
        #     "key": "6898c9eb0ed8ff65bd83180ac32dee06",  # 应用KEY(应用详细页查询)
        # }
        # params = urlencode(params)
        # res = requests.get(url, params)
        # if res:
        #     SMSVerification.objects.create(phone_number=phone_number, code=code)
        #     return Response({'message': '发送成功', 'status': status.HTTP_200_OK}, status=status.HTTP_200_OK)
        # else:
        #     return Response({'message': '发送失败', 'status': 400}, status=status.HTTP_200_OK)
    return Response({'message': '发送成功', 'status': status.HTTP_200_OK, "code": code}, status=status.HTTP_200_OK)
    # data = {
    #     "phone_numer": phone_number,
    #     "code": code
    # }


# 发送邮箱验证码
@api_view(['POST'])
def send_email_code(request):
    email = json.loads(request.body).get('email')
    """
       发送邮箱验证码
       :param to_mail: 发到这个邮箱
       :return: 成功：0 失败 -1
       """
    # 生成邮箱验证码
    sms_code = '%06d' % random.randint(100000, 999999)
    EMAIL_FROM = "free_geek@163.com"  # 邮箱来自
    email_title = '[自由极客]'
    email_body = "您的邮箱验证码为：{0}, 请及时进行验证。".format(sms_code)
    subject = "邮箱验证"
    send_status = send_mail(email_title, email_body, EMAIL_FROM, [email], subject)
    print(send_status)
    if send_status == 1:

        return Response({'message': '发送成功', 'status': status.HTTP_200_OK}, status=status.HTTP_200_OK)
    else:
        return Response({'message': '发送失败', 'status': status.HTTP_200_OK}, status=status.HTTP_200_OK)


# 导出Excel
@api_view(['GET'])
def export_excel(request):
    return Response({'message': '导出成功', 'status': status.HTTP_200_OK}, status=status.HTTP_200_OK)


# 上传图片，视频API
@api_view(['POST'])
def upload_file(request):
    data = request.data.get('file')
    from qiniu import Auth, put_data
    import logging
    if not data:
        return None
    try:
        # 构建鉴权对象
        q = Auth("NwAngZAu-NMd1hnONYBKVLlZIrTl7XvW1003FceC", "0Z80IWpG3UcvHKj9lMedQi83rfV9GKT6WfxvNE1t")
        # 生成上传 Token，可以指定过期时间等
        token = q.upload_token("ziyoujike")
        # 上传文件
        ret, info = put_data(token, None, data)
        print(info)
    except Exception as e:
        logging.error(e)
        raise e

    if info and info.status_code != 200:
        raise Exception("上传文件到七牛云失败")

    # 返回七牛中保存的图片名，这个图片名也是访问七牛获取图片的路径
    print(ret["key"])
    return Response(
        {'data': 'http://qiniuyun.ziyoujike.cn/' + ret["key"], 'message': '上传成功', 'status': status.HTTP_200_OK},
        status=status.HTTP_200_OK)


# 实现注册逻辑
@api_view(['POST'])
def register(request):
    phone_number = request.data.get('phone_number')
    verification_code = request.data.get('code')
    print(phone_number)

    isExist = SMSVerification.objects.filter(phone_number=phone_number, code=verification_code).exists()
    # 查询数据库，检查验证码是否匹配
    print(isExist)
    # 检查用户是否已经存在
    if User.objects.filter(phone_number=phone_number).exists():
        return Response({'message': '用户已存在', 'status': status.HTTP_400_BAD_REQUEST}, status=status.HTTP_400_BAD_REQUEST)
    if isExist:
        # 如果验证码匹配，创建用户，保存到数据库等
        user = User.objects.create(phone_number=phone_number)
        # 保存到数据库
        user.save()
        # 创建用户成功后删除验证码
        SMSVerification.objects.filter(phone_number=phone_number, code=verification_code).delete()
        return Response({'message': '创建成功', 'status': status.HTTP_200_OK}, status=status.HTTP_200_OK)
    else:
        return Response({'message': '验证码不正确', 'status': status.HTTP_400_BAD_REQUEST},
                        status=status.HTTP_400_BAD_REQUEST)


# 实现登录逻辑
@api_view(['POST'])
def login(request):
    phone_number = request.data.get('phone_number')
    user = User.objects.filter(phone_number=phone_number).first()
    verification_code = request.data.get('code')
    # 检查验证码是否匹配
    if SMSVerification.objects.filter(phone_number=phone_number, code=verification_code).exists():
        if user:
            payload = {
                'user_id': str(user.id),
                'exp': datetime.utcnow() + timedelta(days=1)
            }
            token = jwt.encode(payload, settings.SECRET_KEY, algorithm='HS256')

            user_info = {
                'id': user.id,
                'phone_number': user.phone_number,
                'avatar_url': user.avatar_url,
                'user_type': user.user_type,
                'nickname': user.nickname,
                'email': user.email,
                'gender': user.gender,
                'birth_date': user.birth_date,
                'province': user.province,
                'city': user.city,
                'district': user.district,
                'address': user.address,
                'points': user.points,
                'bio': user.bio,
                'created_at': user.created_at,
                'updated_at': user.updated_at
            }
            # 登录成功后删除验证码
            SMSVerification.objects.filter(phone_number=phone_number, code=verification_code).delete()
            return Response({'message': '登录成功', 'token': token, 'user_info': user_info, 'status': status.HTTP_200_OK},
                            status=status.HTTP_200_OK)
        else:
            return Response({'message': '用户不存在', 'status': 400},
                            status=status.HTTP_200_OK)
    else:
        return Response({'message': '验证码不正确', 'status': 400},
                        status=status.HTTP_200_OK)


# 获取用户信息详情
@api_view(['GET'])
def get_user_info(request):
    # token 使用方法
    token = request.headers.get('Authorization')
    try:
        decoded_token = verify_token(token)
        # Now you can access the decoded token's payload
        user_id = decoded_token['user_id']
        try:
            user = User.objects.get(id=user_id)
            user_info = {
                'id': user.id,
                'phone_number': user.phone_number,
                'avatar_url': user.avatar_url,
                'user_type': user.user_type,
                'nickname': user.nickname,
                'email': user.email,
                'gender': user.gender,
                'birth_date': user.birth_date,
                'province': user.province,
                'city': user.city,
                'district': user.district,
                'address': user.address,
                'points': user.points,
                'bio': user.bio,
                'created_at': user.created_at,
                'updated_at': user.updated_at
            }
            return Response({'user_info': user_info, 'message': '查询成功', "status": status.HTTP_200_OK},
                            status=status.HTTP_200_OK)
        except User.DoesNotExist:
            return Response({'message': '用户不存在', 'status': status.HTTP_200_OK}, status=status.HTTP_200_OK)
    except AuthenticationFailed as e:
        # Handle authentication failure
        return Response({'error': str(e)}, status=status.HTTP_401_UNAUTHORIZED)


# 获取用户列表
@api_view(['GET'])
def get_user_list(request):
    # token 使用方法
    # token = request.headers.get('Authorization')
    # try:
    #     decoded_token = verify_token(token)
    #
    #     # Now you can access the decoded token's payload
    #     user_id = decoded_token['user_id']
    #     print(user_id)
    #     # Further logic here...
    # except AuthenticationFailed as e:
    #     # Handle authentication failure
    #     return Response({'error': str(e)}, status=status.HTTP_401_UNAUTHORIZED)
    paginator = PageNumberPagination()
    # 获取用户传递的分页参数，如果没有传递则使用默认值
    page = request.query_params.get('page', 1)
    page_size = request.query_params.get('page_size', 10)
    paginator.page = page
    paginator.page_size = page_size

    users = User.objects.all()
    result_page = paginator.paginate_queryset(users, request)
    serializer = UserSerializer(result_page, many=True)
    return paginator.get_paginated_response(serializer.data)


# 修改用户信息
@api_view(['PUT'])
def update_user_info(request):
    try:
        user = User.objects.get(id=request.data.get('id'))
        serializer = UserSerializer(user, data=request.data, partial=True)
        if serializer.is_valid():
            serializer.save()
            return Response({'message': '修改成功', 'status': status.HTTP_200_OK})
        else:
            return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
    except User.DoesNotExist:
        return Response({'message': '用户不存在', 'status': status.HTTP_400_BAD_REQUEST}, status=status.HTTP_400_BAD_REQUEST)


# 删除用户
@api_view(['DELETE'])
def delete_user(request):
    try:
        user = User.objects.get(id=request.query_params.get('id'))
        user.delete()
        return Response({'message': '删除成功', 'status': status.HTTP_200_OK})
    except User.DoesNotExist:
        return Response({'message': '用户不存在', 'status': status.HTTP_400_BAD_REQUEST}, status=status.HTTP_400_BAD_REQUEST)


# 新增字典
@api_view(['POST'])
def add_dictionary(request):
    data = request.data
    try:
        # Checking if the user exists
        user = User.objects.get(id=data.get('user_id'))
        new_dictionary = Dictionary.objects.create(
            added_by=user,
            name=data.get('name'),
            icon_url=data.get('icon_url'),
            type=data.get('type'),
            code=data.get('code'),
            color=data.get('color')
        )
        new_dictionary.save()

        # Returning success response
        return Response({"message": "创建成功", 'status': status.HTTP_200_OK}, status=status.HTTP_200_OK)
    except User.DoesNotExist:
        return Response({"message": "创建人ID错误", 'status': status.HTTP_400_BAD_REQUEST},
                        status=status.HTTP_400_BAD_REQUEST)


# 编辑字典
@api_view(['PUT'])
def edit_dictionary(request):
    try:
        data = Dictionary.objects.get(id=request.data.get('id'))
        serializer = DictionarySerializer(data, data=request.data, partial=True)
        if serializer.is_valid():
            serializer.save()
            return Response({'message': '修改成功', 'status': status.HTTP_200_OK})
        else:
            return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
    except User.DoesNotExist:
        return Response({'message': '数据不存在', 'status': status.HTTP_400_BAD_REQUEST}, status=status.HTTP_400_BAD_REQUEST)


# 删除字典
@api_view(['DELETE'])
def delete_dictionary(request):
    try:
        data = Dictionary.objects.get(id=request.query_params.get('id'))
        data.delete()
        return Response({'message': '删除成功', 'status': status.HTTP_200_OK})
    except User.DoesNotExist:
        return Response({'message': '资源不存在', 'status': status.HTTP_400_BAD_REQUEST}, status=status.HTTP_400_BAD_REQUEST)


# 获取字典列表
@api_view(['GET'])
def get_dictionary_list(request):

    paginator = PageNumberPagination()
    # 获取用户传递的分页参数，如果没有传递则使用默认值
    page = request.query_params.get('page', 1)
    page_size = request.query_params.get('page_size', 10)
    paginator.page = page
    paginator.page_size = page_size

    data = Dictionary.objects.all()
    result_page = paginator.paginate_queryset(data, request)
    serializer = DictionarySerializer(result_page, many=True)
    return paginator.get_paginated_response(serializer.data)


# 新增分类
@api_view(['POST'])
def add_classification(request):
    data = request.data
    try:
        # Checking if the user exists
        user = User.objects.get(id=data.get('user_id'))
        new_classification = Category.objects.create(
            added_by=user,
            title=data.get('title'),
            description=data.get('description'),
            img_url=data.get('img_url'),
            type=data.get('type'),
        )
        new_classification.save()

        # Returning success response
        return Response({"message": "创建成功", 'status': status.HTTP_200_OK}, status=status.HTTP_200_OK)
    except User.DoesNotExist:
        return Response({"message": "创建人ID错误", 'status': status.HTTP_400_BAD_REQUEST},
                        status=status.HTTP_400_BAD_REQUEST)


# 编辑分类
@api_view(['PUT'])
def edit_classification(request):
    try:
        data = Category.objects.get(id=request.data.get('id'))
        serializer = CategorySerializer(data, data=request.data, partial=True)
        if serializer.is_valid():
            serializer.save()
            return Response({'message': '修改成功', 'status': status.HTTP_200_OK})
        else:
            return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
    except User.DoesNotExist:
        return Response({'message': '数据不存在', 'status': status.HTTP_400_BAD_REQUEST}, status=status.HTTP_400_BAD_REQUEST)


# 删除分类
@api_view(['DELETE'])
def delete_classification(request):
    try:
        data = Category.objects.get(id=request.query_params.get('id'))
        data.delete()
        return Response({'message': '删除成功', 'status': status.HTTP_200_OK})
    except User.DoesNotExist:
        return Response({'message': '资源不存在', 'status': status.HTTP_400_BAD_REQUEST}, status=status.HTTP_400_BAD_REQUEST)


# 获取分类列表
@api_view(['GET'])
def get_classification_list(request):
    paginator = PageNumberPagination()
    # 获取用户传递的分页参数，如果没有传递则使用默认值
    page = request.query_params.get('page', 1)
    page_size = request.query_params.get('page_size', 10)
    type = page = request.query_params.get('type', 0)
    paginator.page = page
    paginator.page_size = page_size
    # 根据分类类型获取全部分类
    if type:
        data = Category.objects.filter(type=type)
        result_page = paginator.paginate_queryset(data, request)
        serializer = CategorySerializer(result_page, many=True)
        return paginator.get_paginated_response(serializer.data)
    # 获取全部分类
    else:
        data = Category.objects.all()
        result_page = paginator.paginate_queryset(data, request)
        serializer = CategorySerializer(result_page, many=True)
        return paginator.get_paginated_response(serializer.data)


# 新增资源
@api_view(['POST'])
def add_resource(request):
    data = request.data
    try:
        # Checking if the user exists
        user = User.objects.get(id=data.get('user_id'))
        category = Category.objects.get(id=data.get('category'))
        new_resource = Resource.objects.create(
            added_by=user,
            category=category,
            title=data.get('title'),
            description=data.get('description'),
            thumbnail=data.get('thumbnail'),
            link=data.get('link'),
            rich_text=data.get('rich_text'),
        )
        new_resource.save()

        # Returning success response
        return Response({"message": "创建成功", 'status': status.HTTP_200_OK}, status=status.HTTP_200_OK)
    except User.DoesNotExist:
        return Response({"message": "创建人ID错误", 'status': status.HTTP_400_BAD_REQUEST},
                        status=status.HTTP_400_BAD_REQUEST)


# 编辑资源
@api_view(['PUT'])
def edit_resource(request):
    try:
        data = Resource.objects.get(id=request.data.get('id'))
        serializer = ResourceSerializer(data, data=request.data, partial=True)
        if serializer.is_valid():
            serializer.save()
            return Response({'message': '修改成功', 'status': status.HTTP_200_OK})
        else:
            return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
    except User.DoesNotExist:
        return Response({'message': '数据不存在', 'status': status.HTTP_400_BAD_REQUEST}, status=status.HTTP_400_BAD_REQUEST)


# 删除资源
@api_view(['DELETE'])
def delete_resource(request):
    try:
        data = Resource.objects.get(id=request.query_params.get('id'))
        data.delete()
        return Response({'message': '删除成功', 'status': status.HTTP_200_OK})
    except User.DoesNotExist:
        return Response({'message': '资源不存在', 'status': status.HTTP_400_BAD_REQUEST}, status=status.HTTP_400_BAD_REQUEST)


# 获取资源列表
@api_view(['GET'])
def get_resource_list(request):
    paginator = PageNumberPagination()
    # 获取用户传递的分页参数，如果没有传递则使用默认值
    page = request.query_params.get('page', 1)
    page_size = request.query_params.get('page_size', 10)
    category = request.query_params.get('category_id')
    if category:
        paginator.page = page
        paginator.page_size = page_size
        data = Resource.objects.filter(category=category)
        result_page = paginator.paginate_queryset(data, request)
        serializer = ResourceSerializer(result_page, many=True)
        for item in serializer.data:
            category_title = Category.objects.get(id=item.get("category")).title
            item.update({"category_title": category_title})
        return paginator.get_paginated_response(serializer.data)

    else:
        paginator.page = page
        paginator.page_size = page_size
        data = Resource.objects.all()
        result_page = paginator.paginate_queryset(data, request)
        serializer = ResourceSerializer(result_page, many=True)
        for item in serializer.data:
            category_title = Category.objects.get(id=item.get("category")).title
            item.update({"category_title": category_title})
        return paginator.get_paginated_response(serializer.data)


# 新增文章博客
@api_view(['POST'])
def add_article_blog(request):
    data = request.data
    try:
        # Checking if the user exists
        user = User.objects.get(id=data.get('user_id'))
        category = Category.objects.get(id=data.get('category'))
        new_data = ArticleBlog.objects.create(
            added_by=user,
            category=category,
            title=data.get('title'),
            description=data.get('description'),
            thumbnail=data.get('thumbnail'),
            rich_text=data.get('rich_text'),
        )
        new_data.save()

        # Returning success response
        return Response({"message": "创建成功", 'status': status.HTTP_200_OK}, status=status.HTTP_200_OK)
    except User.DoesNotExist:
        return Response({"message": "创建人ID错误", 'status': status.HTTP_400_BAD_REQUEST},
                        status=status.HTTP_400_BAD_REQUEST)


# 编辑文章博客
@api_view(['PUT'])
def edit_article_blog(request):
    try:
        data = ArticleBlog.objects.get(id=request.data.get('id'))
        serializer = ArticleBlogSerializer(data, data=request.data, partial=True)
        if serializer.is_valid():
            serializer.save()
            return Response({'message': '修改成功', 'status': status.HTTP_200_OK})
        else:
            return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
    except User.DoesNotExist:
        return Response({'message': '数据不存在', 'status': status.HTTP_400_BAD_REQUEST},
                        status=status.HTTP_400_BAD_REQUEST)


# 删除文章博客
@api_view(['DELETE'])
def delete_article_blog(request):
    try:
        data = ArticleBlog.objects.get(id=request.query_params.get('id'))
        data.delete()
        return Response({'message': '删除成功', 'status': status.HTTP_200_OK})
    except User.DoesNotExist:
        return Response({'message': '资源不存在', 'status': status.HTTP_400_BAD_REQUEST},
                        status=status.HTTP_400_BAD_REQUEST)


# 获取文章博客列表
@api_view(['GET'])
def get_article_blog_list(request):
    paginator = PageNumberPagination()
    # 获取用户传递的分页参数，如果没有传递则使用默认值
    page = request.query_params.get('page', 1)
    page_size = request.query_params.get('page_size', 10)
    category = request.query_params.get('category_id')
    if category:
        paginator.page = page
        paginator.page_size = page_size
        data = ArticleBlog.objects.filter(category=category)
        result_page = paginator.paginate_queryset(data, request)
        serializer = ArticleBlogSerializer(result_page, many=True)
        for item in serializer.data:
            category_title = Category.objects.get(id=item.get("category")).title
            item.update({"category_title": category_title})
        return paginator.get_paginated_response(serializer.data)
    else:
        paginator.page = page
        paginator.page_size = page_size
        data = ArticleBlog.objects.all()
        result_page = paginator.paginate_queryset(data, request)
        serializer = ArticleBlogSerializer(result_page, many=True)
        for item in serializer.data:
            category_title = Category.objects.get(id=item.get("category")).title
            item.update({"category_title": category_title})
        return paginator.get_paginated_response(serializer.data)


# 新增站点收录
@api_view(['POST'])
# def add_site_inclusion(request):
#     data = request.data
#     try:
#         # Checking if the user exists
#         user = User.objects.get(id=data.get('user_id'))
#         category = Category.objects.get(id=data.get('category'))
#         new_data = SiteInclusion.objects.create(
#             added_by=user,
#             category=category,
#             name=data.get('name'),
#             link=data.get('link'),
#             description=data.get('description'),
#             phone_number=data.get('phone_number'),
#             email=data.get('email'),
#             nickname=data.get('nickname'),
#             type=0
#         )
#         new_data.save()
#
#         # Returning success response
#         return Response({"message": "创建成功", 'status': status.HTTP_200_OK}, status=status.HTTP_200_OK)
#     except User.DoesNotExist:
#         return Response({"message": "创建人ID错误", 'status': status.HTTP_400_BAD_REQUEST},
#                         status=status.HTTP_400_BAD_REQUEST)
def add_site_inclusion(request):
    data = request.data

    # Checking if the user exists
    category = Category.objects.get(id=data.get('category'))
    new_data = SiteInclusion.objects.create(
        category=category,
        name=data.get('name'),
        link=data.get('link'),
        description=data.get('description'),
        phone_number=data.get('phone_number'),
        email=data.get('email'),
        nickname=data.get('nickname'),
        type=0
    )
    new_data.save()

    # Returning success response
    return Response({"message": "创建成功", 'status': status.HTTP_200_OK}, status=status.HTTP_200_OK)


# 编辑站点收录
@api_view(['PUT'])
def edit_site_inclusion(request):
    try:
        data = SiteInclusion.objects.get(id=request.data.get('id'))
        serializer = SiteInclusionSerializer(data, data=request.data, partial=True)
        if serializer.is_valid():
            serializer.save()
            return Response({'message': '修改成功', 'status': status.HTTP_200_OK})
        else:
            return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
    except User.DoesNotExist:
        return Response({'message': '数据不存在', 'status': status.HTTP_400_BAD_REQUEST},
                        status=status.HTTP_400_BAD_REQUEST)


# 删除站点收录
@api_view(['DELETE'])
def delete_site_inclusion(request):
    try:
        data = SiteInclusion.objects.get(id=request.query_params.get('id'))
        data.delete()
        return Response({'message': '删除成功', 'status': status.HTTP_200_OK})
    except User.DoesNotExist:
        return Response({'message': '资源不存在', 'status': status.HTTP_400_BAD_REQUEST},
                        status=status.HTTP_400_BAD_REQUEST)


# 获取站点收录列表
@api_view(['GET'])
def get_site_inclusion_list(request):
    paginator = PageNumberPagination()
    # 获取用户传递的分页参数，如果没有传递则使用默认值
    page = request.query_params.get('page', 1)
    page_size = request.query_params.get('page_size', 10)
    category = request.query_params.get('category_id')
    if category:
        paginator.page = page
        paginator.page_size = page_size
        data = SiteInclusion.objects.filter(category=category)
        result_page = paginator.paginate_queryset(data, request)
        serializer = SiteInclusionSerializer(result_page, many=True)
        for item in serializer.data:
            category_title = Category.objects.get(id=item.get("category")).title
            item.update({"category_title": category_title})
        return paginator.get_paginated_response(serializer.data)
    else:
        paginator.page = page
        paginator.page_size = page_size
        data = SiteInclusion.objects.all()
        result_page = paginator.paginate_queryset(data, request)
        serializer = SiteInclusionSerializer(result_page, many=True)
        for item in serializer.data:
            category_title = Category.objects.get(id=item.get("category")).title
            item.update({"category_title": category_title})
        return paginator.get_paginated_response(serializer.data)
